package controllers

import (
	"app/model"
	"app/service"
	"github.com/gin-gonic/gin"
	"github.com/google/uuid"
)

type JobController struct {
}

// Save @Summary		List model.JobInfo
// @Description	post model.JobInfo
// @Tags			model.JobInfo
// @Accept			json
// @Produce		json
// @Param			model.JobInfo	body	model.JobInfo	true	"请输入JobInfo information"
// @Success		200				{array}	model.JobInfo
// @Security     ApiKeyAuth
// @Router			/web/job/save [post]
func (u JobController) Save(c *gin.Context) {
	var jobInfo model.JobInfo
	if err := c.ShouldBindJSON(&jobInfo); err != nil {
		Failed(1, c, err.Error())
		return
	}
	jobInfo.ID = uuid.NewString()
	service.JobService{}.Save(jobInfo)
	Succeed(1, c, nil, 1, nil)
}

// GetById @Summary		List model.JobInfo
// @Description	get model.JobInfo
// @Tags			model.JobInfo
// @Accept			json
// @Produce		json
// @Param			id	query	string	true	"请输入ID"
// @Success		200	{array}	model.JobInfo
// @Security     ApiKeyAuth
// @Router			/web/job/getById [get]
func (u JobController) GetById(c *gin.Context) {
	r := service.JobService{}.Get(c.Query("id"))
	Succeed(1, c, r, 1, nil)
}

// BatchSave @Summary		List model.JobInfo
// @Description	post model.JobInfo
// @Tags			model.JobInfo
// @Accept			json
// @Produce		json
// @Param			model.JobInfo	body	[]model.JobInfo	true	"请输入JobInfo information"
// @Success		200				{array}	model.JobInfo
// @Security     ApiKeyAuth
// @Router			/web/job/batchSave [post]
func (u JobController) BatchSave(c *gin.Context) {
	var jobInfos []model.JobInfo
	if err := c.ShouldBindJSON(&jobInfos); err != nil {
		Failed(1, c, err.Error())
		return
	}

	service.JobService{}.BatchSave(jobInfos)
	Succeed(1, c, nil, 1, nil)
}
